<template>
	<view class="partner">
		<view class="top">
			<u-navbar :is-back="true" title="申请推广人" :border-bottom="false"></u-navbar>
		</view>
		<view class="form-info">
			<u-form :model="formData" ref="form1">
				<u-form-item label="姓名" prop="name" label-width="120"><u-input v-model="formData.name"
						placeholder="请输入姓名" /></u-form-item>
				<u-form-item label="手机" prop="name" label-width="120"><u-input v-model="formData.phone"
						placeholder="请输入手机号码" /></u-form-item>
				<u-form-item label="邀请码" prop="name" label-width="120"><u-input v-model="formData.code"
						placeholder="请输入邀请码" /></u-form-item>

			</u-form>
			<view class="user-agreement">
				<checkbox-group @change="changeRadio">
					<label>
						<checkbox :value="radioValue" :checked="checked" />我已阅读并同意<text class="agreement"
							@click="goAgreement">《用户服务协议及账号隐私保护声明》</text>
					</label>
				</checkbox-group>
			</view>
			<button class="submit-partner" @click="submitForm">提交申请</button>
			<button class="submit-partners" @click="goback">取消</button>
		</view>
	</view>
</template>

<script>
	import { apply } from '../../api/index';
import { toast, toastC } from '../../utils/common';
	export default {
		data() {
			return {
				formData: {
					name: "",
					code: "",
					phone: "",

				},
				checked: false,
				radioValue: ""
			}
		},
		onLoad(res) {
			
			
			console.log("邀请码", res);
			if (res.scene) {
				let str = res.scene
				let index = str.indexOf("3A")
				if (index != -1) {
					let hhh = str.substring(index + 2)
					console.log("hhh", hhh);
					this.formData.code = hhh
					uni.setStorageSync("code", hhh)
				}
			}
			let code = uni.getStorageSync("code") || ''
			console.log("获取",code);
			if (code) {
				this.formData.code = code
			}
			let token = uni.getStorageSync("access_token")
			if (!token) {
				uni.showModal({
					title: '提示',
					content: "你还没有登录,是否去登录",
					cancelText: '取消',
					confirmText: '确定',
					success: function(res) {
						console.log(res);
						if (res.confirm == true) {
							uni.navigateTo({
								url: '/pages/wx-login/wx-login'
							})
						}
			
					},
			
				})
			}
		},

		methods: {

			submitForm() {
				if(!this.formData.name){
					toast("请输入姓名")
					return
				}
				if(!this.formData.phone){
					toast("请输入电话号码")
					return
				}
				apply({
					name:this.formData.name,
					phone:this.formData.phone,
					sales_code:this.formData.code
				}).then(res=>{
					if(res.code==200){
						toastC("申请成功")
						setTimeout(()=>{
							uni.switchTab({
								url:'/pages/home/home'
							},500)
						})
					}
				})
			},

			goAgreement() {
				// uni.navigateTo({
				// 	url:"/pages/app/web"
				// })
			},
			changeRadio(e) {
				// console.log(e)
				this.checked = !this.checked
				// console.log(this.checked)
			},
			goback(){
				uni.redirectTo({
					url:'/pages/home/home'
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	$mainColor: #F3CB99;

	.form-info {
		background-color: #ffffff;
		border-radius: 10rpx;
		padding: 20rpx;
	}

	.partner {
		// background: url(https://img.js.design/assets/img/636cfa22e2e0e5d0b224cdfc.jpg#7c98f63261630120c5c689c1c6a7240d) no-repeat;
		// background-size: 100% 100%;
		width: calc(100vw - 80rpx);
		height: 100vh;
		position: relative;
		top: 0;
		left: 0;
		padding: 40rpx;
	}

	.form-title {
		// color: $mainColor;
		color: black;
		font-size: 40rpx;
		font-weight: 700;
		text-align: center;
		margin-bottom: 40rpx;
	}

	.submit-partner {
		border-radius: 30rpx;
		background-color: #941320;
		color: #ffffff;

	}
	.submit-partners {
		border-radius: 30rpx;
		background-color: #dedede;
		color: #333;
		margin-top: 20rpx;
	
	}

	.approved {
		margin-top: 20rpx;
		font-size: 36rpx;
		text-align: center;
		color: #1AAD19;
	}

	.user-agreement {
		text-align: center;
		margin: 25rpx 0;

		.agreement {
			text-decoration: underline;
			margin-left: 5rpx;
		}
	}
</style>